package com.borened.common.boot.security;

import cn.hutool.crypto.SecureUtil;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;

/**
 * Security BCrypt加密器 工具使用类
 *
 * @author: cch
 * @since: 2021/11/5
 */
public class BCryptEncoderUtil {

    public static final BCryptPasswordEncoder encodeer = new BCryptPasswordEncoder();

    /**
     * 加密
     *
     * @param sourceStr
     * @return
     */
    public static String encode(String sourceStr) {
        return encodeer.encode(sourceStr);
    }

    /**
     * 判断密码是否相同
     *
     * @param rawPassword     真实密码
     * @param encodedPassword 加密后字符
     * @return 结果
     */
    public static boolean matches(String rawPassword, String encodedPassword) {
        return encodeer.matches(rawPassword, encodedPassword);
    }

    public static String md5Encode(String rawStr) {
        return SecureUtil.md5(rawStr);
    }

}
